package com.st.lotte.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.st.lotte.model.Code;
import com.st.lotte.model.TLO_DELY_TRCE_RECV_IF;
import com.st.lotte.util.DBUtil;
import com.st.lotte.util.Database;
import com.st.lotte.util.LogTrace;

public class CodeDAO {
private static final Logger log = LoggerFactory.getLogger(CodeDAO.class);
	
	Connection conn = null;
	Database db = new Database();
	
	public CodeDAO(){
		conn = db.getConnection();
	}
	
	protected synchronized void finalize() throws Throwable {
		conn.close();
	}; 
	
	public synchronized Vector<Code> getCodeLists() {
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		Vector<Code> list = new Vector<Code>();
		try {
			String sql = DBUtil.GET_CODELIST;
			pstmt = conn.prepareStatement(sql);
			rs = pstmt.executeQuery();
			while (rs.next()) {
				Code dto = new Code();
				dto.setCode(rs.getString("code"));
				dto.setName(rs.getString("name"));
				list.add(dto);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		LogTrace.TraceLog("[code dao] Complete!!");
		
		return list;
	}
}
